package com.qingcheng.dao;

import com.qingcheng.pojo.order.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.time.LocalDate;
import java.util.Set;

public interface OrderMapper extends Mapper<Order> {

/*
* 人数统计
* 数量统计
* 金额统计
* */

    /**
     * 查询付款人数 (待完善)
     * 已支付状态 pay_status='1'
     * 更新时间
     * 查询所有username,存入set集合,集合长度为当天下单用户数量
     *
     * @return
     * @param date
     */

    @Select("select username  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} and is_delete='0' and pay_status='1' ")
    public Set<String> findOrdersPeopleNum(@Param("date") LocalDate date);


    /**
     * 查询下单人数
     * 查询所有username,存入set集合,集合长度为当天下单用户数量
     *
     * @return
     */

    @Select("select username  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} ")
    public Set<String> findPaymentPeopleNum(@Param("date") LocalDate date);

    /**
     * 查询订单数量
     * 查询当天产生的订单总数
     * @param date
     * @return
     */
    @Select("select count(id)  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} ")
    public Integer findAllOrderNum(@Param("date") LocalDate date);

    /**
     * 查询有效订单数量
     * 未删除订单总数,其中order_status='1'为
     * @param date
     * @return
     */
    @Select("select count(id)  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} and is_delete='0' ")
    public Integer findOrderSuccessNum(@Param("date") LocalDate date);


    /**
     * 查询付款订单数量
     * 付款订单总数,其中order_status='1' pay_status='1'
     * @param date
     * @return
     */
    @Select("select count(id)  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} and is_delete='0' and pay_status='1' ")
    public Integer findPayOrderNum(@Param("date") LocalDate date);

    /**
     * 查询订单商品数量
     * 全部订单商品总数
     * @param date
     * @return
     */
    @Select("select sum(total_num)  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} ")
    public Integer findAllGoodsNum(@Param("date") LocalDate date);

    /**
     * 查询付款订单商品数量
     * 付款订单商品累加
     * @param date
     * @return
     */
    @Select("select sum(total_num)  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} and is_delete='0' and pay_status='1' ")
    public Integer findPayGoodsNum(@Param("date") LocalDate date);


    /**
     * 查询所有订单总金额
     * 付款订单总额累加
     * @param date
     * @return
     */
    @Select("select sum(total_money)  " +
            "from tb_order " +
            "where is_delete='0' and DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} ")
    public Integer findPlaceMoney(@Param("date") LocalDate date);

    /**
     * 查询所有退款总金额(未删除,已退款.实付金额)
     * 退款订单实付金额累加
     * @param date
     * @return
     */
    @Select("select sum(pay_money)  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} and is_delete='0' and pay_status='2' ")
    public Integer findRefundMoney(@Param("date") LocalDate date);

    /**
     * 查询实付总金额(未删除,实付金额)
     * 已付订单实付金额累加
     * @param date
     * @return
     */
    @Select("select sum(pay_money)  " +
            "from tb_order " +
            "where DATE_FORMAT( tb_order.`create_time`,'%Y-%m-%d') = #{date} and is_delete='0' and pay_status='1' ")
    public Integer findPayMoney(@Param("date") LocalDate date);
}
